use "./IGOsSocializationUNGD_dataset_ISQ.dta", clear


log using "./log_IGOsSocializationUNGD_ISQ.smcl"


egen iso_num = group(iso)

xtset iso_num year

gen PR_wordscore=presrus_wscore*100

gen PU_wordscore=presus_wscore*100


gen Europe=0
replace Europe=1 if ccode>199&ccode<400




**** Main Results (Table 1) - EU association on FP position for Global and Europe *******


xtreg PR_wordscore L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEURus

xtreg PU_wordscore L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEUUsa


xtreg PR_wordscore L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEURus_europe


xtreg PU_wordscore L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEUUSA_europe


estout ModelEURus ModelEUUsa ModelEURus_europe ModelEUUSA_europe, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)




******* Main Results (Table 2) - EU Years on FP Position *****
 
 
mkspline yearsp = year, cubic displayknots
 
xtreg PR_wordscore eu_years polity2 log_GDPpc tradeopen unsc postcoldwar yearsp* if eu_total>2, fe vce(cluster iso_num)
est store ModelMemberyearsRus

xtreg PU_wordscore eu_years polity2 log_GDPpc tradeopen unsc postcoldwar yearsp* if eu_total>2 & e(sample), fe vce(cluster iso_num)
est store ModelMemberyearsUS

estout ModelMemberyearsRus ModelMemberyearsUS, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)



 
 ******** Robustness Checks (Supplementary Materials) ***********************


***** Pre-accession period combined **************

xtreg PR_wordscore L.eu_member L.preaccess_only polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEURus_preaccess

xtreg PU_wordscore L.eu_member L.preaccess_only polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEUUSA_preaccess


xtreg PR_wordscore L.eu_member L.preaccess_only polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEURus_preaccess_europe

xtreg PU_wordscore L.eu_member L.preaccess_only polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEUUSA_preaccess_europe


estout ModelEURus_preaccess ModelEUUSA_preaccess ModelEURus_preaccess_europe ModelEUUSA_preaccess_europe, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)



****** Additional controls **************


xtreg PR_wordscore L.(i.eu_total) polity2 rus_tradeshare log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEURus_trade

xtreg PU_wordscore L.(i.eu_total) polity2 usa_tradeshare log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEUUSA_trade


xtreg PR_wordscore L.(i.eu_total) polity2 rus_tradeshare log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEURus_trade_europe

xtreg PU_wordscore L.(i.eu_total) polity2 usa_tradeshare log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEUUSA_trade_europe


estout ModelEURus_trade ModelEUUSA_trade ModelEURus_trade_europe ModelEUUSA_trade_europe, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)



**** Analysis with Cosine and Jaccard similarity ***********


xtset iso_num year


xtreg presC L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store Modelcosine_global

xtreg presJ L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store Modeljaccard_global

xtreg presC L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store Modelcosine_europe

xtreg presJ L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store Modeljaccard_europe

estout Modelcosine_global Modeljaccard_global Modelcosine_europe Modeljaccard_europe , cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)



********** Analysis with RWMD *********************************


xtreg pres_rwmd L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store Modelrwmd_global

xtreg pres_rwmd L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store Modelrwmd_europe

estout Modelrwmd_global Modelrwmd_europe , cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)


********** Analysis with Wordscores with Words Appearing in One Year Only Dropped ******************


gen PR_wordscore_dw=presrus_wscore_dw*100

gen PU_wordscore_dw=presus_wscore_dw*100



xtreg PR_wordscore_dw L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEURusdw

xtreg PU_wordscore_dw L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)
est store ModelEUUsadw


xtreg PR_wordscore_dw L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEURus_europedw


xtreg PU_wordscore_dw L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year if Europe==1, fe vce(cluster iso_num)
est store ModelEUUSA_europedw


estout ModelEURusdw ModelEUUsadw ModelEURus_europedw ModelEUUSA_europedw, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)



********* Analysis of EU Years on FP Position (with alternative text similarity measures ****************


*mkspline yearsp = year, cubic displayknots


xtreg presC eu_years polity2 log_GDPpc tradeopen unsc postcoldwar yearsp* if eu_total>2, fe vce(cluster iso_num)
est store ModelMemberyearscosine

xtreg presJ eu_years polity2 log_GDPpc tradeopen unsc postcoldwar yearsp* if eu_total>2, fe vce(cluster iso_num)
est store ModelMemberyearsjaccard

xtreg pres_rwmd eu_years polity2 log_GDPpc tradeopen unsc postcoldwar yearsp* if eu_total>2, fe vce(cluster iso_num)
est store ModelMemberyearsrwmd


estout ModelMemberyearscosine ModelMemberyearsjaccard ModelMemberyearsrwmd, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_clust r2_a r2_o rmse, fmt(0 0 3 3 3) label(N NCountries AdjR2 OverallR2 RMSE)) starlevels(+ 0.10 ** 0.05 *** 0.001) modelwidth(4)


**** Summary Statistics ***********************

xtset iso_num year

quietly xtreg PR_wordscore L.(i.eu_total) polity2 log_GDPpc tradeopen unsc postcoldwar i.year, fe vce(cluster iso_num)

sutex2 PR_wordscore PU_wordscore  eu_member euoa_only eucs_only eu_years preaccess_only polity2 log_GDPpc tradeopen unsc postcoldwar rus_tradeshare usa_tradeshare presC presJ pres_rwmd if e(sample)==1, minmax

*********

log close
